bitkeeper revision 1.1108.35.7 (410a0b93obztTzgYAKS6IcEBh3xJcQ)
authormjw@wray-m-3.hpl.hp.com <mjw@wray-m-3.hpl.hp.com>
Fri, 30 Jul 2004 08:49:23 +0000 (08:49 +0000)
committermjw@wray-m-3.hpl.hp.com <mjw@wray-m-3.hpl.hp.com>
Fri, 30 Jul 2004 08:49:23 +0000 (08:49 +0000)
Use environment variables XEND and XEND_ROOT to set the location
of the xend server and its root path.

tools/python/xen/xend/XendClient.py

index 1bb7a094f271ddbceeb0058c3e285449e33d0472..cc5b06fd102dbabb0ac0050a33920a5f2aebc348 100644 (file)
@@ -9,6 +9,7 @@ The 'data-plane' is done separately. For example, consoles
 are accessed via sockets on xend, but the list of consoles
 is accessible via this API.
 """
+import os
 import sys
 import httplib
 import types
@@ -331,9 +332,15 @@ class Xend:
     """Default location of the xend server."""
     SRV_DEFAULT = "localhost:8000"
 
+    """Environment variable to set the location of xend."""
+    SRV_VAR = "XEND"
+
     """Default path to the xend root on the server."""
     ROOT_DEFAULT = "/xend/"
 
+    """Environment variable to set the xend root path."""
+    ROOT_VAR = "XEND_ROOT"
+
     def __init__(self, client=None, srv=None, root=None):
         """Create a xend client interface.
         If the client protocol is not specified, the default
@@ -348,14 +355,24 @@ class Xend:
         self.client = client
         self.bind(srv, root)
 
+    def default_server(self):
+        """Get the default location of the xend server.
+        """
+        return os.getenv(self.SRV_VAR, self.SRV_DEFAULT)
+
+    def default_root(self):
+        """Get the default root path on the xend server.
+        """
+        return os.getenv(self.ROOT_VAR, self.ROOT_DEFAULT)
+
     def bind(self, srv=None, root=None):
         """Bind to a given server.
 
         @param srv:  server location (host:port)
         @param root: xend root path on the server
         """
-        if srv is None: srv = self.SRV_DEFAULT
-        if root is None: root = self.ROOT_DEFAULT
+        if srv is None: srv = self.default_server()
+        if root is None: root = self.default_root()
         if not root.endswith('/'): root += '/'
         (host, port) = srv.split(':', 1)
         self.url = URL(host=host, port=port, path=root)